//
//  MainViewController.m
//  WebRTCDemo_iOS
//
//  Created by szblsx2 on 2020/3/7.
//  Copyright © 2020 szblsx2. All rights reserved.
//

#import "MainViewController.h"
#import "HomeViewController.h"
#import "ChatVieViewController.h"
#import "KLSdk.h"

@interface MainViewController ()

@property (weak, nonatomic) IBOutlet UIButton *initializeButton;

@property (weak, nonatomic) IBOutlet UIButton *creatButton;

@property (weak, nonatomic) IBOutlet UIButton *joinButton;

@end

@implementation MainViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"百灵一会";
    self.creatButton.layer.borderColor = UIColor.lightGrayColor.CGColor;
    self.creatButton.layer.borderWidth = 1.0;
    self.joinButton.layer.borderColor = UIColor.lightGrayColor.CGColor;
    self.joinButton.layer.borderWidth = 1.0;
    //创建随机名字
    NSUInteger num = arc4random_uniform(99) + 1;
    NSString *name = [NSString stringWithFormat:@"Guest%zd",num];
    //    [[KLSdk shared] initSDKWithServer:@"120.238.78.214" port:@"9443" name:name];
    [[KLSdk shared] initSDKWithServer:@"192.168.2.234" port:@"9443" name:name];
    
  
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:45/255.f green:45/255.f blue:57/255.f alpha:1.0];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor],
                                                                      NSFontAttributeName : [UIFont fontWithName:@"Helvetica-Bold" size:17]}];
}

- (IBAction)creatButtonAction:(UIButton *)sender
{
    //创建随机房间Id
    NSUInteger num = arc4random_uniform(99) + 1;
    NSString *roomId = [NSString stringWithFormat:@"room%zd",num];
    [[KLSdk shared] createMeetingWithRoomId:roomId];
    ChatVieViewController *chatVc = [ChatVieViewController new];
    chatVc.roomId = roomId;
    chatVc.modalPresentationStyle = UIModalPresentationOverFullScreen;
    [self presentViewController:chatVc animated:YES completion:nil];
}

- (IBAction)joinButtonAction:(UIButton *)sender
{
    [self.navigationController pushViewController:[HomeViewController new] animated:YES];
}

@end
